import confirmModal from '~/components/modal/confirm-modal.vue';
import {useModal} from "vue-final-modal";

/**
 * 弹框函数
 * @param title
 * @param content
 * @param confirmFunction 确认事件
 * @param callback 回调事件
 */
export const useConfirmDialog = (title: string, content: string, confirmFunction: Function, callback: Function) => {
    const {open, close} = useModal({
        component: confirmModal,
        attrs: {
            title: title,
            content: content,
            onConfirm() {
                const confirm = confirmFunction();
                if (confirm) {
                    callback();
                    close().then(r => {
                    });
                }
            },
            onClose() {
                close().then(r => {
                });
            }
        }
    })
    open().then(r => {
    });
}

